package com.cjh.admin.controller;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.cjh.admin.config.TokenThreadLocal;
import com.cjh.common.dto.ClerkPagingDTO;
import com.cjh.common.entity.Store;
import com.cjh.common.entity.StoreOrder;
import com.cjh.common.mapper.StoreMapper;
import com.cjh.common.mapper.StoreOrderMapper;
import com.cjh.common.response.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.*;

@RestController
@RequestMapping("/dataDisplay")
public class DataDisplayController {
    @Autowired
    StoreOrderMapper storeOrderMapper;
    @Autowired
    StoreMapper storeMapper;
    @ApiOperation("获取数据统计")
    @GetMapping("/getDataDisplay")
    public Result getAllClerk(){
        List<Store> stores = storeMapper.selectList(Wrappers.<Store>lambdaQuery().select(Store::getStoreId, Store::getName));
        List<List> moneyChartData = new ArrayList();
        List<List> numberOfOrdersData = new ArrayList();
        for (int i = 0; i < stores.size(); i++) {
            Store store = stores.get(i);
            List<Map<String, Object>> maps = storeOrderMapper.selectEchartData(store.getStoreId());
            ArrayList<String> tList = new ArrayList<>();
            tList.add("date");
            List nList = new ArrayList();
            List mList = new ArrayList();
            nList.add(store.getName());
            mList.add(store.getName());
            for (Map<String,Object> m : maps){
                tList.add(m.get("RT").toString());
                nList.add(m.get("RN"));
                mList.add(m.get("RM"));
            }
            if(i==0){
                numberOfOrdersData.add(0,tList);
                moneyChartData.add(0,tList);
            }
            numberOfOrdersData.add(i+1,nList);
            moneyChartData.add(i+1,mList);
        }
        HashMap<String, Object> stringObjectHashMap = new HashMap<>();
        stringObjectHashMap.put("moneyChartData",moneyChartData);
        stringObjectHashMap.put("numberOfOrdersData",numberOfOrdersData);
        stringObjectHashMap.putAll(storeOrderMapper.selectAllData());
        stringObjectHashMap.putAll(storeOrderMapper.selectTodayData());
        stringObjectHashMap.putAll(storeOrderMapper.selectYesterdayData());
        stringObjectHashMap.putAll(storeOrderMapper.selectRecentSevenDaysData());
        stringObjectHashMap.putAll(storeOrderMapper.selectInThisMonthData());
        return new Result().setCode(200).setMessage("获取成功").setData(stringObjectHashMap);
    }
}
